package com.kiln.juxingqs.ui.vm


import android.app.Application
import androidx.lifecycle.MutableLiveData
import client.global.commlib.network.data.JsonResult
import client.global.commlib.network.data.Ret
import com.kiln.juxingqs.ui.viewmodel.MiddleVm
import com.kiln.juxingqs.api.bean.UserAddress
import com.kiln.juxingqs.api.bean.UserCards

class BankManagerViewModel(app: Application) : MiddleVm(app) {

    val cardListRet = MutableLiveData<JsonResult<UserCards>>()
    val delRet = MutableLiveData<JsonResult<Ret>>()

    val isLoading = MutableLiveData<Boolean>(false)
    val isShowing = MutableLiveData<Boolean>(false)
    val isRef = MutableLiveData<Boolean>(false)

    fun holdCall() {
        if (isLoading.value!!)
            return
        hold({
            server.user_card_list()
        }, {
            isLoading.value = true
        }, success = {
            cardListRet.value = it
        }, complete = {
            isLoading.value = false
        })
    }


    fun delCard(tokenNo: String) {
        hold(
            {
                server.un_bind_card(tokenNo)
            },
            {
                isLoading.value = true
            }, {
                delRet.value = it
            }, {
            }, {
                isLoading.value = false
            }
        )
    }
}